package com.icongyou.enterprise.auth.service.impl;

import com.icongyou.enterprise.auth.service.UpdateUserService;
import com.icongyou.enterprise.common.result.Result;
import com.icongyou.enterprise.data_aggregation.entity.UserEntity;
import com.icongyou.enterprise.data_aggregation.mapper.DataAggregationMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UpdateUserServiceImpl implements UpdateUserService {

    @Resource
    private DataAggregationMapper dataAggregationMapper;

    @Override
    public Result updateUserInfo(UserEntity userEntity) {
        int rowsAffected = dataAggregationMapper.updateUserInfo(userEntity);
        if (rowsAffected > 0) {
            UserEntity updatedUser = dataAggregationMapper.getUserById(userEntity.getId());
            return Result.success("更新用户信息成功。",updatedUser);
        } else {
            return Result.error("更新用户信息失败，未找到对应用户。");
        }
    }

    @Override
    public Result getUserById(String userId) {
        UserEntity user = dataAggregationMapper.getUserById(userId);
        if (user != null) {
            return Result.success("查询用户信息成功。", user);
        } else {
            return Result.error("未找到对应用户信息。");
        }
    }
}
